package cn.tedu._06article.controller;

import cn.tedu._06article.base.response.JsonResult;
import cn.tedu._06article.base.response.StatusCode;
import cn.tedu._06article.mapper.UserMapper;
import cn.tedu._06article.pojo.dto.UserLonginParam;
import cn.tedu._06article.pojo.vo.UserVO;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@Tag(name = "01-用户管理模块")
@RequestMapping("/v1/user")
public class UserController {
	@Autowired
	private UserMapper userMapper;
	
	@PostMapping("/login")
	@Operation(summary = "登录")
	@ApiOperationSupport(order = 10)
	public JsonResult login(@RequestBody UserLonginParam userLoginParam, HttpSession session) {
		log.debug("开始处理【登录】" + userLoginParam);
		
		UserVO userVO = userMapper.selectByUsernameAndPassword(userLoginParam);
		if (userVO == null) {
			return JsonResult.ok(StatusCode.USERNAME_PASSWORD_ERROR);
		}
		session.setAttribute("user", userVO);
		
		return JsonResult.ok(userVO);
	}
}
